package online.heycm.platform.rocketmq.publisher;

import online.heycm.platform.rocketmq.common.handler.DefaultLocalTransactionHandler;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 事件驱动自动装配
 *
 * @author heycm
 * @since 2023/12/2 20:48
 */
@Configuration
@ConditionalOnProperty(value = "rocketmq.name-server")
public class EventAutoConfiguration {

    @Bean
    public DefaultLocalTransactionHandler defaultLocalTransactionHandler() {
        return new DefaultLocalTransactionHandler();
    }

    @Bean
    public DefaultSendCallback defaultSendCallback() {
        return new DefaultSendCallback();
    }

    @Bean
    public EventTransactionListener eventTransactionListener() {
        return new EventTransactionListener();
    }

    @Bean
    public EventPublisher eventService(RocketMQTemplate rocketMQTemplate,
            EventTransactionListener eventTransactionListener) {
        return new EventPublisherImpl(rocketMQTemplate, eventTransactionListener);
    }
}
